extends Control

@onready var label:Label = $Label

var data
var container
var battleField

func _ready():
	battleField = get_tree().get_nodes_in_group("BattleField")[0]


func init(menuItemData):
	data = menuItemData
	label.text = data.name
	

func hasSubMenuitem():
	return data.subMenuItemsData.size() > 0
	

func _physics_process(delta):
	processInput()
		

func processInput():
	if not visible: return
	
	if Input.is_action_just_pressed("mouse_left_button"):
		var mousePosition = Global.getMousePosition()
		var mouseWorldPos = Global.view2WorldPos(mousePosition, battleField.cam)
		if mouseWorldPos.x <= global_position.x + size.x and mouseWorldPos.x >= global_position.x and mouseWorldPos.y <= global_position.y + size.y and mouseWorldPos.y >= global_position.y:
			container.onMenuItemClick(self)
		
